<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,maximum-scale=1.0" />
    <title><#if entity.userId??>编辑<#else>新增</#if>用户</title>
    <#include "/view/admin/head.html"/>
    <script type="text/javascript" src="${base}/jstool/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
    <script type="text/javascript" src="${base}/jstool/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
    <link rel="stylesheet" type="text/css" href="${base}/jstool/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" />

    <script type="text/javascript" src="${base}/jstool/bootstrap-switch/bootstrap-switch.min.js"></script>
    <link rel="stylesheet" type="text/css" href="${base}/jstool/bootstrap-switch/bootstrap-switch.min.css" />
    <script type="text/javascript" src="${base}/jstool/bootstrap-validator-0.5.3/js/bootstrapValidator.min.js"></script>
    <script type="text/javascript" src="${base}/jstool/bootstrap-validator-0.5.3/lang/zh_CN.min.js"></script>
    <link rel="stylesheet" type="text/css" href="${base}/jstool/bootstrap-validator-0.5.3/css/bootstrapValidator.min.css" />


    <style type="text/css">
        .list-path {
            height: 50px;
            line-height: 50px;
            background-color: #9acfea;
        }

        .table-class {
            width: 90%;
            text-align: center;
            border: 1px solid #afd9ee;
            margin: 0 auto;
            margin-top: 50px;
        }

        table th {
            width: 20%;
            background-color: #d9edf7;
            text-align: right;
        }

        table td {
            width: 20%;
            text-align: left;
        }


    </style>
    <script type="text/javascript">

        $(function(){
            //初始化
            $('#shangjia').click(function(){
                if($("#shangjia").is(':checked')){
                    if (window.confirm("是否要创建商家?")) {
                        var str='';
                        str+="  <tr id='phone'>";
                        str+="                  <th>联系电话</th>";
                        str+="                  <td>";
                        str+='                  <input type="text" class="form-control" name="phone" placeholder="请输入联系电话" value="">';
                        str+="                  </td>";
                        str+="                </tr>";
                        $(str).insertBefore($('#oper'));
                    }else{
                        return false;
//                        $('#shangjia').attr("checked", "");
                    }
                }else{
                    if (window.confirm("是否要关闭商家?")) {
                        $('#phone').remove();
                    }else{
                        return false;
//                        $('#shangjia').attr("checked", true);
                    }
                }
            });


            $('[name="iscreatecb"]').bootstrapSwitch({
                onText:"是",
                offText:"否",
                onColor:"success",
                offColor:"info",
                size:"small",
                onSwitchChange:function(event,state){
                    if(state==true){
                        $(this).val("1");
                        $('[name="iscreate"]').val("1");
                        $("#div1").show();
                        $("#spanid1").text("商家电话");
                    }else{
                        $(this).val("0");
                        $('[name="iscreate"]').val("0");
                        $("#div1").hide();
                        $("#phone").val("");
                        $("#spanid1").text("");
                        
                    }
                }
            });






            $('#xyuserForm').bootstrapValidator({
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {


                    username: {
                        message: '输入用户名出错',
                        validators: {
                            notEmpty: {
                                message: '用户名不能为空'
                            },
                            stringLength: {
                                max: 19,
                                message: '用户名不能超过 19个字符'
                            }
                        }
                    }

                    ,
                    password: {
                        message: '输入密码出错',
                        validators: {
                            notEmpty: {
                                message: '密码不能为空'
                            },
                            stringLength: {
                                max: 40,
                                message: '密码不能超过 40个字符'
                            }
                        }
                    }

                    ,
                    nickname: {
                        message: '输入昵称出错',
                        validators: {
                            notEmpty: {
                                message: '昵称不能为空'
                            },
                            stringLength: {
                                max: 19,
                                message: '昵称不能超过 19个字符'
                            }
                        }
                    }


                }
            });


        });

    </script>
</head>
<body>

<#include "/view/admin/listnav.html"/>


<div class="table-class">
    <#include "/view/admin/opermsg.html"/>
    <form id="xyuserForm" action="${base}/xyuser/save.do"
    >
        <table class="table table-bordered">

            <input type="hidden" style="display: none" name="userId" value="${entity.userId!}"/>


            <tr>
                <th>用户名</th>
                <td>
                    <div class="form-group">
                        <input type="text" class="form-control" id="username" name="username" placeholder="请输入用户名" value="${entity.username!}">
                    </div>
                </td>

            </tr>

            <tr>
                <th>昵称</th>
                <td>
                    <div class="form-group">
                        <input type="text" class="form-control" id="nickname" name="nickname" placeholder="请输入昵称" value="${entity.nickname!}">
                    </div>
                </td>

            </tr>
            <#if entity.userId??>
                <#else>
            <tr>

                <th>密码</th>
                <td>
                    <div class="form-group">
                        <input type="text" class="form-control" id="password" name="password" placeholder="请输入密码" value="${entity.password!}">
                    </div>
                </td>
            </tr>
                </#if>

            <tr>

                <th>角色</th>
                <td>
                    <div class="form-group">

                        <#list rolelist as role>
                            <input type="checkbox" name="roleId" value="${role.roleId!}"
                                   <#if '商家'==role.name> id="shangjia"</#if>
                                   <#if 1==role.checked>checked="true"</#if>
                            />${role.name!}</input>&nbsp;
                        </#list>


                    </div>
                </td>
            </tr>

            <#list rolelist as role>
                <#if '商家'==role.name&&role.checked==1>
                <tr id="phone">
                    <th>联系电话</th>
                    <td>
                        <input type="text" class="form-control" name="phone" placeholder="请输入联系电话" value="${entity.phone!}">
                    </td>
                </tr>
                </#if>
            </#list>




            <tr id="oper">
                <td colspan="2" width="100%" style="text-align: center;">
                    <input type="submit" class="btn btn-success " value="保存"/>
                    <span style="width: 20px;">&nbsp;</span>
                    <a class="btn btn-danger " href="javascript:window.history.go(-1)">
                        </span>返回</a>
                </td>
            </tr>

        </table>
    </form>




</div>

<script type="text/javascript">

</script>


</body>
</html>
